import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import edu.gatech.spacetraderteam3.controller.GUIEventHandler;
import edu.gatech.spacetraderteam3.model.Game;
import edu.gatech.spacetraderteam3.view.Assets;
import edu.gatech.spacetraderteam3.view.SGGWM;

/**
 * Driver class.
 * 
 * @author Aaron
 * @version 19
 */
public class Driver {
    /**
     * Width of the screen
     */
    private static final int WIDTH = 800;
    /**
     * Height of the screen
     */
    private static final int HEIGHT = 600;

    /**
     * Main method that starts the whole game.
     * 
     * @param args
     *            Command-line arguments
     * @throws IOException
     *             FileIO problems.
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                final JFrame demo = new JFrame("Space Trader");
                demo.setMinimumSize(new Dimension(WIDTH, HEIGHT));
                demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                final Game game = new Game();
                @SuppressWarnings("serial")
                final JPanel contentPanel = new JPanel() {
                    public void paintComponent(Graphics g) {
                        super.paintComponent(g);
                        final Graphics2D g2 = (Graphics2D) g;
                        game.paint(g2, getWidth(), getHeight());
                        Toolkit.getDefaultToolkit().sync();
                        g2.dispose();
                    }
                };
                SGGWM.registerContainer(contentPanel);
                final BufferedImage cursorImage = Assets.CursorType.MAIN.image();
                final Cursor cursor = Toolkit.getDefaultToolkit()
                        .createCustomCursor(cursorImage, new Point(0, 0), "Main Cursor");
                contentPanel.setCursor(cursor);
                contentPanel.addKeyListener(GUIEventHandler.getKeyListener());
                demo.add(contentPanel);
                demo.pack();
                demo.setVisible(true);
                contentPanel.requestFocusInWindow();
            }
        });
    }

    /**
     * ToString for Driver class. Should never really be seen, but just in case. *
     * 
     * @see java.lang.Object#toString()
     * @return Driver
     */
    public String toString() {
        return "Driver! You shouldn't be seeing this...";
    }
}
